package com.ethink.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 前置filter
 *
 * @author wanghaiyong
 */
@Slf4j
public abstract class AbstractPreFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        // 前置过滤
        ServerWebExchange serverWebExchange = preFilter(exchange);
        Mono<Void> result = chain.filter(serverWebExchange);
        return result;
    }

    /**
     * 前置业务
     *
     * @param exchange
     * @return
     */
    protected abstract ServerWebExchange preFilter(ServerWebExchange exchange);
}
